package com.etong.citymap.activity;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.etong.citymap.bean.ToDayBean;
import com.etong.citymap.connect.HttpSendData;
import com.etong.citymap.db.util.CityApplication;
import com.etong.citymap.util.log.LogUtil;

/**
 * 提示详情
 */
public class ToDayCueDetailedActivity extends Activity {
	ToDayBean dayBean;
	LinearLayout back;
	TextView title;
	TextView date;
	TextView content;

	private CityApplication cityApplication;
	Handler handler = new Handler(new Handler.Callback() {

		@Override
		public boolean handleMessage(Message msg) {
			
			if(msg.what==3){
				String result=msg.getData().getString("data");
				if (result.equals("-3")) {
				} else if (result.equals("-1")) {
					Toast.makeText(ToDayCueDetailedActivity.this, "操作错误",
							Toast.LENGTH_SHORT).show();
				} else if (result.equals("1")) {
					Toast.makeText(ToDayCueDetailedActivity.this, "已读取成功",
							Toast.LENGTH_SHORT).show();
				} 
			}
			return false;
		}
	});

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detailed);
		cityApplication = (CityApplication)getApplication();
		dayBean = (ToDayBean) this.getIntent().getSerializableExtra("bean");
		back = (LinearLayout) findViewById(R.id.detailed_back);
		title = (TextView) findViewById(R.id.detailed_title);
		date = (TextView) findViewById(R.id.detailed_date);
		content = (TextView) findViewById(R.id.detailed_content);
		back.setOnClickListener(onClickListener);
		if (dayBean != null) {
			title.setText(dayBean.getTitle());
			date.setText(dayBean.getTipdate());
			content.setText(dayBean.getContent());
			new TiJiaoData();
		}
	}

	class TiJiaoData extends Thread {
		public TiJiaoData() {
			start();
		}

		@Override
		public void run() {
			if(dayBean.getIsread().equals("0")){
				String url = "supervisor/ashx/TipRead.ashx"; // 001 001
				Map<String, String> map = new HashMap<String, String>();
				map.put("superid", dayBean.getSuperid());
				map.put("tipflag", dayBean.getTipflag());
				try {
					String result = HttpSendData.SendGet(url, map, "utf-8",cityApplication.getHTTPURL());
					Message msg=new Message();
					msg.getData().putString("data", result);
					msg.what=3;
					handler.sendMessage(msg);
				} catch (Exception e) {
					LogUtil.e(e);
				}
			}
		}

	}

	private OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			finish();
		}
	};

}
